package com.example.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class Spinner extends Activity implements OnItemSelectedListener {

	private TextView text;
	private final String[] items =	{"make", "angel", "crow", "john", "ginnie", "sally", "cohen", "rice"};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_spinner);
		
		text =	(TextView)findViewById(R.id.selectedItem);
		
		android.widget.Spinner spinner =	(android.widget.Spinner)findViewById(R.id.spinner);
		spinner.setOnItemSelectedListener(this);
		
		ArrayAdapter<String> adapter =	new ArrayAdapter<String>(
			this, android.R.layout.simple_spinner_dropdown_item, items);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		
		spinner.setAdapter(adapter);
	}

	@Override
	public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		text.setText(items[arg2]);
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		text.setText("");
	}

}
